package com.neusoft.controller;

import com.neusoft.core.User;
import com.neusoft.core.VirtualWallet;
import com.neusoft.service.VirtualWalletService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

@RestController
@RequestMapping("/VirtualWalletController")
public class VirtualWalletController {
    @Autowired
    private VirtualWalletService virtualWalletService;
    @GetMapping("/{walletId}")
    public com.neusoft.core.CommonResult<VirtualWallet> getVirtualWallet(@PathVariable Integer walletId) {
        VirtualWallet wallet = virtualWalletService.getVirtualWallet(walletId);
        return new com.neusoft.core.CommonResult<>(200, "获取钱包信息成功", wallet);
    }

    @PostMapping("/{walletId}/credit")
    public void credit(@PathVariable Integer walletId, @RequestParam BigDecimal amount) {
        virtualWalletService.credit(walletId, amount);
    }

    @PostMapping("/{walletId}/debit")
    public void debit(@PathVariable Integer walletId, @RequestParam BigDecimal amount) {
        virtualWalletService.debit(walletId, amount);
    }

    @PostMapping("/transfer")
    public void transfer(
        @RequestParam("fromWalletId") Integer fromWalletId, 
        @RequestParam("toWalletId") Integer toWalletId, 
        @RequestParam("amount") BigDecimal amount) {
        virtualWalletService.transfer(fromWalletId, toWalletId, amount);
    }

    @PostMapping("/create")
    public com.neusoft.core.CommonResult<Integer> saveVirtualWallet(@RequestParam String userId) {
        Integer walletId = virtualWalletService.saveVirtualWallet(userId);
        return new com.neusoft.core.CommonResult<>(200, "钱包创建成功", walletId);
    }
}
